package com.hyk.learning.provider;

import com.hyk.learning.circuitBreaker.CircuitBreaker;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: CircuitBreakerProvider
 * @author: hyk199710
 * @description: 熔断器提供接口
 * @date: 2024/9/6 0:48
 */
public class CircuitBreakerProvider {
    public Map<String, CircuitBreaker> circuitBreakerMap = new HashMap<>();

    public CircuitBreaker getCircuitBreaker(String serviceName){
        CircuitBreaker circuitBreaker;
        if(circuitBreakerMap.containsKey(serviceName)){
            circuitBreaker = circuitBreakerMap.get(serviceName);
        }
        else{
            circuitBreaker = new CircuitBreaker(3, 0.5, 10000);
            circuitBreakerMap.put(serviceName, circuitBreaker);
        }
        return circuitBreaker;
    }
}
